import { SET_USER,CLEAR_USER } from "../actionTypes"

const initState = {
    user: {
        id: 1,
        username: "",
        email: "",
        mobile: "",
        token: "",
    }
}

export const userReducer = (state = initState, action) => {
    const { type, payload=1 } = action
    switch (type) {
        case SET_USER:
            return { ...state, user: payload }
        case CLEAR_USER:
            return {
                ...state, user: {
                    id: 1,
                    username: "",
                    email: "",
                    mobile: "",
                    token: "",
                }
            }
        default:
            return state
    }
}
